package com.xl.basic.config;

import com.xl.basic.entity.Properties;
import com.xl.basic.utils.PropUtils;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 钟勇
 * Create in 2024/1/18 13:44
 */
@Configuration
@RequiredArgsConstructor
public class WxMpConfig {

    private final Properties prop;
    @Bean
    public WxMpService wxMpService() {
        Properties.WxMp wxMp = prop.getWxMp();
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(wxMp.getAppId());
        config.setSecret(wxMp.getAppSecret());
        config.setToken(wxMp.getToken());
        config.setAesKey(wxMp.getAesKey());

        WxMpService wxService = new WxMpServiceImpl();
        wxService.setWxMpConfigStorage(config);

        return wxService;
    }
}
